<template>
  <div class="home">
    <div class="top">
      <div class="current" :class="needshow ? 'active' : ''">
        <myinput @showstate="show" @getipt="getipt" v-model="content" @sendnum="getnum"></myinput>
        <mylist
          v-show="needshow == true"
          @getcontent="getcontent"
          :num="num"
        ></mylist>
      </div>
      <button @click="add">百度一下</button>
    </div>
  </div>
</template>

<script>
import myinput from "@/components/myinput";
import mylist from "@/components/mylist";

export default {
  name: "Home",
  components: { myinput, mylist },
  data() {
    return {
      needshow: false,
      content: "",
      num: -1,
      
    };
  },
  methods: {
    show(val) {
      this.needshow = val;
    },
    getipt(data) {
      this.content = data;
    },
    add() {
      this.$store.commit("changelist", {
        type: "add",
        content: this.content,
        id: new Date().getTime(),
      });
     
    },
    getcontent(data) {
      this.content = data;
    },
    getnum(num) {
      this.num = num;
    },
  },
  mounted() {
    document.addEventListener("click", (e) => {
      if (e.target.className != "ipt" && e.target.className != "btn") {
        this.needshow = false;
      }
    });
  },
  watch:{
    
    content(){

    }
  }
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  .top {
    width: 60%;
    margin: 50px auto;
    display: flex;
    justify-content: center;
    .current {
      width: 400px;
      border: 1px solid gainsboro;
      border-top-left-radius: 6px;
      border-bottom-left-radius: 6px;
    }
    .active {
      width: 400px;
      border: 1px solid rgb(10, 171, 235);
      border-top-left-radius: 6px;
      border-bottom-left-radius: 6px;
      border-bottom-right-radius: 6px;
    }
    button {
      width: 100px;
      height: 42px;
      background-color: rgb(10, 171, 235);
      color: #fff;
      outline: 0;
      border: 0;
      border-top-right-radius: 6px;
      border-bottom-right-radius: 6px;
    }
  }
}
</style>
